package Class026;

import java.util.HashMap;
import java.util.HashSet;

//unorderedMap
public class Hash {
    public static void main(String[] args) {
        maps();
    }

    public static void maps() {
        //Integer, Double, Long, Float
        //Byte, Short, Character, Boolean
        //String都有这个特征：
        //Set去重只是按照值去重，地址不鸟
        String str1 = new String("Hello");
        String str2 = new String("Hello");

        System.out.println("地址是否相同:" + str1 == str2);
        System.out.println("值是否相同" + str1.equals(str2));

        HashSet<String> strSet = new HashSet<>();
        HashMap<String, String> strMap = new HashMap<>();
        strSet.add(str1);
        System.out.println("Set是否有str2的值:" + strSet.contains(str2));

        strMap.put("Hello", "World");
        System.out.println("Map是否有Hello这个key:" + strMap.containsKey(str1));

        //如果是自己定义的类，记录的key是64位/8字节的内存地址
        Student s1 = new Student(10, "张三");
        Student s2 = new Student(10, "张三");
        HashSet<Student> stuSet = new HashSet<>();
        stuSet.add(s1);
        System.out.println("虽然两人信息一致，会不会认为已经存在相同的对象 : " + stuSet.contains(s2));
    }

    public static class Student {
        public int age;
        public String name;

        public Student(int age, String name) {
            this.age = age;
            this.name = name;
        }
    }
}
